﻿using Developer.Core.FrameWork.EventBus.Model;
using System;
using System.Collections.Generic;

namespace Developer.Core.FrameWork.EventBus.Service
{
    /// <summary>
    /// 事件订阅总线管理器
    /// </summary>
    public interface IEventBusSubscriptionsManager
    {
        bool IsEmpty { get; }

        event EventHandler<string> onEventRemoved;

        /// <summary>
        /// 动态添加订阅
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="eventName"></param>
        void AddDynamicSubscription<T>(string eventName) where T : IDynamicEventHandler;

        /// <summary>
        /// 添加订阅
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TH"></typeparam>
        void AddSubscription<T, TH>() where T : EventModel where TH : IEventHandler;

        /// <summary>
        /// 移除订阅
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TH"></typeparam>
        void RemoveSubscription<T, TH>() where T : EventModel where TH : IEventHandler<T>;

        /// <summary>
        /// 动态移除订阅
        /// </summary>
        /// <typeparam name="T"></typeparam>
        void RemoveDynamicSubscription<T>(string eventName) where T : IDynamicEventHandler;

        /// <summary>
        /// 是否在某个事件上有订阅
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="eventName"></param>
        /// <returns></returns>
        bool HasSubscriptionForEvent<T>() where T : EventModel;

        /// <summary>
        /// 是否在某个事件上有订阅
        /// </summary>
        /// <param name="eventName"></param>
        /// <returns></returns>
        bool HasSubscriptionForEvent(string eventName);

        /// <summary>
        /// 获取事件类型
        /// </summary>
        /// <param name="eventName"></param>
        /// <returns></returns>
        Type GetEventTypeByName(string eventName);

        /// <summary>
        /// 清除所有订阅
        /// </summary>
        void Clear();

        /// <summary>
        /// 获取订阅事件所有处理程序
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IEnumerable<SubscriptionInfo> GetHandlerForEvent<T>() where T : EventModel;

        IEnumerable<SubscriptionInfo> GetHandlerForEvent(string eventName);

        /// <summary>
        /// 获取事件key
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        string GetEventKey<T>();
    }
}
